home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / 20arieel.zip / Bin / weeknum.arx < prev   
Text File  |  1996-06-19  |  2KB  |  65 lines

  1. /******************************************************************************/
  2. /* Copyright 1995 (C) by Andreas Haack
  3. ** $Id: weeknum.arx,v 1.5 1996/06/02 10:19:22 hak Exp $
  4. *******************************************************************************
  5. ** week numbering - rexx
  6. ** $Log: weeknum.arx,v $
  7. ** Revision 1.5  1996/06/02 10:19:22  hak
  8. ** supply year ast 4th parameter to weeknumber rexx function
  9. **
  10. ** Revision 1.4  1996/05/08 23:43:49  hak
  11. ** intermidiate level
  12. ** with config
  13. **
  14. ** Revision 1.3  1996/03/04 23:39:36  hak
  15. ** APR000000000: Corenction
  16. ** uses start of week
  17. ** corrected calulation
  18. **
  19. ** Revision 1.2  1996/01/30 20:12:51  hak
  20. ** corrected problem with 4.th week in 2000
  21. ** no bWeekstart on needed anymore
  22. **
  23. ** Revision 1.1  1996/01/23 22:00:53  hak
  24. ** Initial revision
  25. **
  26. *******************************************************************************/
  27.  
  28. /*******************************************************************************
  29. A year has 52 weeks plus 1 or 2 days if 1st jan is a fri - son the week counts
  30. to prev year thus it is still 53rd week otherwise week count to this year
  31. dayOfYear = 0 .. 364,365, weekday 0-6 0 = sun
  32. *******************************************************************************/
  33. trace('O');
  34.  
  35. parse arg weekday, dayOfYear, bStartOnSunday, year .
  36.  
  37. weekday = (weekday + (\ bStartOnSunday * 6)) // 7;
  38. dow1st = ((7 - (dayOfYear // 7)) + weekday) // 7;                                 /* week day of 1st week sun = 0*/
  39. week = (dayOfYear + dow1st) % 7;                                           /* 0 based week number */
  40. thisYear = dow1st < 4;                                                          /* if most part of 1st week belongs to this year*/
  41.  
  42. select
  43.     when week = 0 then
  44.         select
  45.             when dow1st = 4 then
  46.                 week = 53;
  47.             when dow1st > 4 then
  48.                 week = 52;
  49.             otherwise
  50.                 week = 1;
  51.         end
  52.     when week = 52 then
  53.         select
  54.             when dow1st = 3 then
  55.                 week = 53;
  56.             when dow1st > 3 then
  57.                 week = 52;
  58.             otherwise
  59.                 week = 1;
  60.         end
  61.     otherwise
  62.         week = week + thisYear;
  63. end
  64. return week;
  65.